<?php
include_once dirname(__FILE__)."/common/basic.php";
include_once dirname(__FILE__)."/common/pages.class.php";
if($_GET[downloadReply]){
	/*if(!$func->hasLogedIn()){
		$refer = urlencode($_SERVER[REQUEST_URI]);
		$func->redirect2("login.php?refer=$refer");
		die();
	}*/
	$reply = $func->qiu_get_reply($_GET[downloadReply]);
	if($reply){
		$client_ip = $_SERVER[REMOTE_ADDR];
		if(!$func->allow_download($reply[id],$client_ip)){
			$func->error("w12100704","下载过于频繁！");
		}
		
		$func->recordDownload($reply[id],$_SESSION[uid],$client_ip);
		$func->qiu_incDownload($reply[id]);
		if($reply[lx]=="torrent"){
			$filepath = $func->getFilePathByFID($reply[fid]);
			if(!$filepath){
				$func->error("e12100702","找不到该文件信息");
			}
			$file = $func->getFileById($reply[fid]);
			$fname = "【比特圈】【bitzone.co】".$file[name];
			$func->downloadFile($filepath, $fname);
		}else if($reply[link]){
			$func->redirect($reply[link]);
		}else{
			$func->error("e12100703","找不到该下载");
		}
	}else{
		$func->error("e12100701","找不到该下载");
	}
	die();
}
if($_POST[qiu]){
	if($func->qiu_create($_POST[zymc],$_POST[zysm],$_POST[tzyx])){
		echo 1;
	}else{
		echo 0;
	}
	die();
}
if($_POST[qiu_id]){
	$qiu_id = $_POST[qiu_id];
	$lx = $_POST[lx];
	$reply_id = null;
	if($lx=="torrent"){
		if($_FILES[torrent]){
			$file = array(
				'name'=>$_FILES[torrent][name],
				'type'=>'torrent',
				'tmp_name'=>$_FILES[torrent][tmp_name],
				'size'=>$_FILES[torrent][size],
				'error'=>$_FILES[torrent][error]
			);
			if($file[size]>1024*1024){
				$func->error("e12062601","上传的.torrent文件不得大于1MB");
			}
			$fid = $func->saveFile($_SESSION[uid], $file);
			$reply_id = $func->qiu_reply($qiu_id,'torrent',$fid,"",$_POST[fname_torrent],$file[size],$_POST[ly],$_POST[mail]);
		}
	}elseif($lx=="ed2k"){
		$fsize = $func->ed2k_size($_POST[ed2k]);
		$reply_id = $func->qiu_reply($qiu_id,'ed2k',"",$_POST[ed2k],$_POST[fname_ed2k],$fsize,$_POST[ly],$_POST[mail]);
	}elseif($lx=="magnet"){
		$reply_id = $func->qiu_reply($qiu_id,'magnet',"",$_POST[magnet],$_POST[fname_magnet],"null",$_POST[ly],$_POST[mail]);
	}elseif($lx=="thunder"){
		$reply_id = $func->qiu_reply($qiu_id,'thunder',"",$_POST[thunder],$_POST[fname_thunder],"null",$_POST[ly],$_POST[mail]);
	}
	if($reply_id){
		$func->qiu_notify($qiu_id,$reply_id,$config);
	}
	$func->redirect("qiu.php?page=".$_GET[page]);
}
$page = $_GET[page];
if(!$page){
	$page=1;
}
$pagesize = 20;
$total = $func->qiu_query_count();
$posts = $func->qiu_query($page,$pagesize);
pageft($total,$pagesize);

if($_GET[show]){
	$show_post = $func->qiu_get($_GET[show]);
	if($show_post){
		$show_post[show]=true;
		if(!$posts){
			$posts = array();
		}
		array_push($posts, $show_post);
	}
}

$tl->set_file("qiu");
$tl->p();
?>